package com.cy.pj.modules.service.impl;

import com.cy.pj.common.bo.PageObject;
import com.cy.pj.modules.entity.Shop;
import com.cy.pj.modules.mapper.ShopMapper;
import com.cy.pj.modules.service.IShopService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 商家信息Service业务层处理
 *
 * @author kiven
 * @date 2023-02-09
 */
@Service("shopServiceImpl")
public class ShopServiceImpl implements IShopService
{
    @Autowired
    private ShopMapper shopMapper;

    @Value("${fz.pageHelper.pageSize}")
    private Integer pageSize;
    /**
     * 查询商家信息
     *
     * @param id 商家信息ID
     * @return 商家信息
     */
    @Override
    public Shop selectShopById(Long id)
    {
        return shopMapper.selectShopById(id);
    }

    /**
     * 查询商家信息列表
     *
     * @param shop 商家信息
     * @return 商家信息
     */
    @Override
    public PageObject<Shop> selectShopList(Shop shop, Integer pageCurrent)
    {
        //1.参数校验
        if(pageCurrent==null||pageCurrent<1) {
            throw new IllegalArgumentException("页码值无效");
        }
        //2.设置分页参数
        String orderBy = "create_time desc";
        Page<Shop> page= PageHelper.startPage(pageCurrent,pageSize,orderBy);
        //3.查询当前页记录
        List<Shop> list= shopMapper.selectShopList(shop);
        return new PageObject<Shop>(list, (int)page.getTotal(), page.getPages(), pageSize, pageCurrent);
    }

    @Override
    public List<Shop> selectShopList1() {
        return shopMapper.selectShopList1();
    }


    /**
     * 新增商家信息
     *
     * @param shop 商家信息
     * @return 结果
     */
    @Override
    public int insertShop(Shop shop)
    {
        shop.setCreateTime(new Date());
        return shopMapper.insertShop(shop);
    }

    /**
     * 修改商家信息
     *
     * @param shop 商家信息
     * @return 结果
     */
    @Override
    public int updateShop(Shop shop)
    {
        shop.setModifyTime(new Date());
        return shopMapper.updateShop(shop);
    }

    /**
     * 删除商家信息对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteShopByIds(String ids)
    {
        String[] ids1=ids.split(",");
        return shopMapper.deleteShopByIds(ids1);
    }

    /**
     * 删除商家信息信息
     *
     * @param id 商家信息ID
     * @return 结果
     */
    @Override
    public int deleteShopById(Long id)
    {
        return shopMapper.deleteShopById(id);
    }
}
